package com.small.mybatis.binding;

import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @Author zhoujin
 * @Date 2022/3/31 20:29
 */
public class MapperProxyFactory<T> {

    private final Class<T> mapperInterface;

    public MapperProxyFactory(Class<T> mapperInterface){
        this.mapperInterface = mapperInterface;
    }

    public T newInstance(Map<String,String> sqlSession){
        MapperProxy<T> mapperProxy = new MapperProxy(sqlSession, mapperInterface);
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(),new Class[]{mapperInterface}, mapperProxy);
    }
}
